const asc = require('@/plugins/md5.js')
const CryptoJS = require('@/plugins/aesUtil.js')

const key = CryptoJS.enc.Utf8.parse("7b5bad595e239000"); //十六位十六进制数作为秘钥
const iv = CryptoJS.enc.Utf8.parse('5c84c203069aac00'); //十六位十六进制数作为秘钥偏移量

//解密方法
export function decrypt(value) {
	const encryptedHexStr = CryptoJS.enc.Hex.parse(value);
	const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
	const decrypt = CryptoJS.AES.decrypt(srcs, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
	return decryptedStr.toString();
}

//加密方法
export function encrypt(word) {
	const srcs = CryptoJS.enc.Utf8.parse(word);
	const encrypted = CryptoJS.AES.encrypt(srcs, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}